﻿using Logger.Service.Interface;
using NLog;
using System;
using System.Collections.Generic;
using System.Text;

namespace Logger.Service
{
    /// <summary>
    /// 日志管理
    /// </summary>
    public class NLogService : ILoggerContext
    { 
        private NLog.Logger _logger;

        public NLogService()
        {
            _logger = NLog.LogManager.GetCurrentClassLogger();
        } 

        public void Process(string UserName, string Logger, string msg)
        {
            LogEventInfo lei = new LogEventInfo();
            lei.Properties["UserName"] = UserName;
            lei.Properties["Logger"] = Logger;
            lei.Level = LogLevel.Trace;
            lei.Message = msg;
            _logger.Log(lei);
        }

        public void ProcessError(int statusCode, string msg)
        {
            LogEventInfo lei = new LogEventInfo();
            lei.Properties["Logger"] = Convert.ToString(statusCode);
            lei.Level = LogLevel.Error;
            lei.Message = msg;
            _logger.Log(lei);
        }

        #region Debug
        public void Debug(string msg, params object[] args)
        {
            _logger.Debug(msg, args);
        }

        public void Debug(string msg, Exception err)
        {
            _logger.Debug(err, msg);
        }
        #endregion

        #region Info
        public void Info(string msg, params object[] args)
        {
            _logger.Info(msg, args);
        }

        public void Info(string msg, Exception err)
        {
            _logger.Info(err, msg);
        }
        #endregion

        #region Warn
        /// <summary>
        /// 
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="args"></param>
        public void Warn(string msg, params object[] args)
        {
            _logger.Warn(msg, args);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="err"></param>
        public void Warn(string msg, Exception err)
        {
            _logger.Warn(err, msg);
        }
        #endregion

        #region Error
        /// <summary>
        /// 
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="args"></param>
        public void Error(string msg, params object[] args)
        {
            _logger.Error(msg, args);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="err"></param>
        public void Error(string msg, Exception err)
        {
            _logger.Error(err, msg);
        }
        #endregion


    }
}